package org.example.web;

import com.sun.xml.internal.ws.wsdl.writer.UsingAddressing;
import org.example.pojo.User;
import org.example.service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "Login", value = "/Login")
public class Login extends HttpServlet {
     UserService userService = new UserService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String username = request.getParameter("username");
        String password = request.getParameter("password");

        User login = userService.login(username, password);

        request.getSession().setAttribute("user",login);
        if(login != null){
            //登录成功
            System.out.println("登录成功");
            request.getRequestDispatcher("/ipfs.html").forward(request,response);

        }else{
            //登录失败，


            System.out.println("登录失败");
            //跳转
            request.getRequestDispatcher("/login.html").forward(request,response);
        }


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);

    }
}
